package com.woniuxy.threeprojcet.end_water_project_admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.threeprojcet.end_water_project_admin.dao.UserMapper;
import com.woniuxy.threeprojcet.end_water_project_admin.domain.User;
import com.woniuxy.threeprojcet.end_water_project_admin.domain.form.UserForm;
import com.woniuxy.threeprojcet.end_water_project_admin.service.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-08-26
 */
@RestController
@Slf4j
@CrossOrigin("*")
@RequestMapping("/admin")
public class UserController {

    @Resource

    private UserServiceImpl userService;
    @Resource
    private UserMapper userMapper;
//获得用户表
    @GetMapping("getUser")
    public IPage getUser( @RequestParam(name = "pageSize", defaultValue = "4") int pageSize,
                         @RequestParam(name = "current", defaultValue = "1") int current) {

        IPage page = new Page(current, pageSize);


        IPage<User> user = userService.getUser(page);
        return user;
    }


    @PostMapping("updateUserState")
    public boolean updateUserState(@RequestBody UserForm userForm){
        log.info("水表ID：{}",userForm);
        int i = userService.updateUserStateByWaterMeterId(userForm.getWaterMeterId());
        return i>0? true:false;
    }





}

